/**
 * 详情对话框
 */
var GcgWsjdInfoDlg = {
    tableId: "menuTable",
    data: {
        gcgWsjdId: "",
        gcgProjectId: "",
        yaoma: "",
        mingcheng: "",
        dizhiSheng: "",
        dizhiShengView: "",
        dizhiShi: "",
        dizhiShiView: "",
        dizhiXianqu: "",
        dizhiXianquView: "",
        dizhiXiangxi: "",
        pinpai: "",
        guishu: "",
        mdTel: "",
        lxrName: "",
        lxrTel: "",
        jsTel: "",
        pinlei: "",
        mdYysj: "",
        isTcw: "",
        tcwPrice: "",
        renjunPrice: "",
        farenXingming: "",
        yhkName: "",
        yhkHao: "",
        isFapiao: "",
        isYouhui: "",
        farenSfzPic1: "",
        farenSfzPic2: "",
        farenSfzPic3: "",
        dzSfzPic1: "",
        dzSfzPic2: "",
        dzSfzPic3: "",
        yingyeZhizhao: "",
        shipinXkz: "",
        zfbShouquan: "",
        mentouPics: "",
        neijingPics: "",
        shStatus: "",
        createTime: "",
        createUser: "",
        updateTime: "",
        updateUser: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects','tree','ztree','treetable','table'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var tree = layui.tree;
    var $ZTree = layui.ztree;
    var treetable = layui.treetable;
    var table = layui.table;

    /**
     * 初始化表格的列
     */
    GcgWsjdInfoDlg.initColumn = function () {
        return [[
            // {type: 'numbers'},
            {type: 'checkbox'},
            {field: 'gcgWsjdShenpixiangId', hide: true, sort: true, title: 'id'},
            {field: 'name', align: "left", sort: false, title: '支付宝口碑', minWidth: 240},
            {field: 'miaoshu', align: "left", sort: false, title: '驳回原因', minWidth: 240,edit: 'text'},
        ]];
    };

    __log = function(msg) {
        setTimeout(() => {
            throw new Error(msg);
        }, 0);
    }


    // GcgWsjdInfoDlg.Rebut = function (data) {
    //     var checkRows = table.checkStatus(GcgWsjdInfoDlg.tableId);
    //     var data = checkRows.data;
    //     // data.forEach((item, i) => {
    //     //     if(item.miaoshu.length == 0) {
    //     //         Feng.error("请填写驳回原因");
    //     //         return
    //     //     }
    //     // });
    //     if (checkRows.data.length === 0) {
    //         Feng.error("请选择要批量完成的数据");
    //     } else {
    //         var ajax = new $ax(Feng.ctxPath + "/gcgWsjd/zfbReject", function (data) {
    //             Feng.success("已驳回!");
    //             table.reload(GcgWsjdInfoDlg.tableId);
    //
    //             var index = parent.layer.getFrameIndex(window.name);
    //             parent.layer.close(index);//关闭当前页
    //         }, function (data) {
    //             Feng.error("驳回失败!" + data.responseJSON.message + "!");
    //         });
    //         ajax.set("id", $("#gcgWsjdId").val());
    //         ajax.set("data", JSON.stringify(data));
    //         ajax.start();
    //     }
    // };



    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var checkRows = table.checkStatus(GcgWsjdInfoDlg.tableId);
        var data = checkRows.data;
        if (!data.length){
            Feng.error("请选择要批量完成的数据");
            return
        }
        var tempList = ["basic","zhengjian","md_tel"]
        for (let i=0; i<data.length;i++){
            debugger
            if(data[i].miaoshu.length == 0 && tempList.indexOf(data[i].code) < 0) {
                Feng.error("请填写驳回原因");
                return
            }
        }

        var ajax = new $ax(Feng.ctxPath + "/gcgWsjd/zfbReject", function (data) {
            Feng.success("驳回成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("驳回失败！" + data.responseJSON.message)
        });
        ajax.set("id", $("#gcgWsjdId").val());
        ajax.set("data", JSON.stringify(data));
        ajax.start();

    });


    /**
     * 初始化表格
     */
    GcgWsjdInfoDlg.initTable = function (menuId, data) {
        return treetable.render({
            elem: '#' + menuId,
            url: Feng.ctxPath + '/gcgWsjd/rejectList',
            // url: Feng.ctxPath + '/gcgWsjd/rejectList?gcgWsjdId=' +  Feng.getUrlParam("gcgWsjdId"),
            where: data,
            page: false,
            height: "full-98",
            cellMinWidth: 100,
            cols: GcgWsjdInfoDlg.initColumn(),
            treeColIndex: 2,
            treeSpid: "0",
            treeIdName: 'gcgWsjdShenpixiangId',
            treePidName: 'pid',
            done:function (res,data) {
                $('th[data-field=' + 0 +'] input[type="checkbox"]').prop('disabled', true);
                res.data.forEach(function (item, index) {
                    if (item.name === "基本信息") {
                        $(".layui-table").find('tr[data-index="'+ index +'"]').find('td').data('edit', false);
                        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('disabled', true);

                    }
                    if (item.name === "前厅/客服电话") {
                        $(".layui-table").find('tr[data-index="'+ index +'"]').find('td').data('edit', false);
                        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('disabled', true);
                    }
                    if (item.name === "证件信息") {
                        $(".layui-table").find('tr[data-index="'+ index +'"]').find('td').data('edit', false);
                        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('disabled', true);
                    }
                })

                // $(".layui-table").find('tr[data-index="'+ 0 +'"]').find('td').data('edit', false);
                // $(".layui-table").find('tr[data-index="'+ 6 +'"]').find('td').data('edit', false);
                // $(".layui-table").find('tr[data-index="'+ 9 +'"]').find('td').data('edit', false);
            }
        });
    };

    // 渲染表格
    var tableResult = GcgWsjdInfoDlg.initTable(GcgWsjdInfoDlg.tableId);
    $('#expandAll').click(function () {
        treetable.expandAll('#' + GcgWsjdInfoDlg.tableId);
    });
    $('#foldAll').click(function () {
        treetable.foldAll('#' + GcgWsjdInfoDlg.tableId);
    });


    //初始化左侧部门树
    var ztree = new $ZTree("menuTree", "/gcgWsjd/rejectTreeList");
    ztree.bindOnClick(GcgWsjdInfoDlg.onClickMenu);
    // ztree.init();


    // 驳回按钮点击事件
    $('#btnSearch').click(function () {
        GcgWsjdInfoDlg.Rebut();
    });


});